package com.ruoyi.ebike.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ebike.vo.CouponRecordVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ebike.domain.CouponRecord;
import com.ruoyi.ebike.service.ICouponRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠券购买记录Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/coupon_record/coupon_record")
public class CouponRecordController extends BaseController
{
    @Autowired
    private ICouponRecordService couponRecordService;

    /**
     * 查询优惠券购买记录列表
     */
    @PreAuthorize("@ss.hasPermi('coupon_record:coupon_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(CouponRecordVO couponRecordVO)
    {
        startPage();
        List<CouponRecordVO> list = couponRecordService.selectCouponRecordVOList(couponRecordVO);
        return getDataTable(list);
    }

    /**
     * 导出优惠券购买记录列表
     */
    @PreAuthorize("@ss.hasPermi('coupon_record:coupon_record:export')")
    @Log(title = "优惠券购买记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponRecordVO couponRecordVO)
    {
        List<CouponRecordVO> list = couponRecordService.selectCouponRecordVOList(couponRecordVO);
        ExcelUtil<CouponRecordVO> util = new ExcelUtil<CouponRecordVO>(CouponRecordVO.class);
        util.exportExcel(response, list, "优惠券购买记录数据");
    }

    /**
     * 获取优惠券购买记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('coupon_record:coupon_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(couponRecordService.selectCouponRecordById(id));
    }

    /**
     * 新增优惠券购买记录
     */
    @PreAuthorize("@ss.hasPermi('coupon_record:coupon_record:add')")
    @Log(title = "优惠券购买记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponRecord couponRecord)
    {
        return toAjax(couponRecordService.insertCouponRecord(couponRecord));
    }

    /**
     * 修改优惠券购买记录
     */
    @PreAuthorize("@ss.hasPermi('coupon_record:coupon_record:edit')")
    @Log(title = "优惠券购买记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponRecord couponRecord)
    {
        return toAjax(couponRecordService.updateCouponRecord(couponRecord));
    }

    /**
     * 删除优惠券购买记录
     */
    @PreAuthorize("@ss.hasPermi('coupon_record:coupon_record:remove')")
    @Log(title = "优惠券购买记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(couponRecordService.deleteCouponRecordByIds(ids));
    }
}
